package com.shanjupay.merchant.service.impl;

import com.shanjupay.common.domain.BusinessException;
import com.shanjupay.common.domain.CommonErrorCode;
import com.shanjupay.common.oss.QiNiuCloudClient;
import com.shanjupay.merchant.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *     文件操作服务类
 * </p>
 */
@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private QiNiuCloudClient qiNiuCloudClient;

    @Override
    public String upload(byte[] data, String fileName) {
        String accessUrl = "";
        try {
            qiNiuCloudClient.upload2cloud(data, fileName);
            accessUrl = qiNiuCloudClient.getUrl() + fileName;
        } catch (Exception e) {
            throw new BusinessException(CommonErrorCode.E_100106);
        }
        return accessUrl;
    }
}
